//Tue Apr 26 09:35:09 CDT 2011
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class MathContest {
public:
	int countBlack(string ballSequence, int repetitions) {
		int sz = ballSequence.size();
		int n = repetitions * sz;
		int showed = 0;
		int low = 0;
		int high = n - 1;
		bool neg = false;
		bool rev = false;
		while (low <= high) {
			int x = (rev == true ? high-- : low++);
			bool isBlack = (ballSequence[x % sz] == 'B');
			if (isBlack ^ neg) {
				showed++;
				neg ^= true;
			} else {
				rev ^= true;
			}
		}
		return showed;
	}
};

